package com.hz.qs.controller;

import cn.hutool.core.util.IdUtil;
import com.hz.qs.model.YiCallPatient;
import com.hz.qs.service.DoctorService;
import com.hz.qs.utils.RestResult;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("doctor/")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @ApiOperation("根据科室代码获取可用队列")
    @GetMapping("getQueueByDeptCode")
    public RestResult getQueueByDeptCode(@RequestParam String deptCode) {
        return doctorService.getQueueByDeptCode(deptCode);
    }

    @ApiOperation("医生端获取客户列表")
    @GetMapping("getCustomerDataByDept")
    public RestResult getCustomerDataByDept(@RequestParam String currentDate, @RequestParam String queueId, String customerName) {
        return doctorService.getCustomerDataByDept(currentDate, queueId, customerName);
    }

    @ApiOperation("叫号")
    @PostMapping("callPatient")
    public RestResult callPatient(@RequestBody YiCallPatient callPatient) {
        try {
            String uuid = IdUtil.fastSimpleUUID();
            callPatient.setId(uuid);
            Integer integer = doctorService.callPatient(callPatient);
            if (integer > 0) {
                return RestResult.successResult(uuid);
            } else {
                return RestResult.failResult("该人员已在检查中，不能进行叫号！！", 4002);
            }
        } catch (Exception e) {
            log.error(e.getMessage());
            return RestResult.failResult("叫号失败！", 500);
        }
    }

    @ApiOperation("医生叫号轮询")
    @GetMapping("docLoopTips")
    public RestResult docLoopTips(@RequestParam String customerId, @RequestParam String currentDate) {
        return doctorService.docLoopTips(customerId, currentDate);
    }

    @ApiOperation("医生取消叫号")
    @GetMapping("docCancelCall")
    public RestResult docCancelCall(@RequestParam String id) {
        try {
            return doctorService.docCancelCall(id);
        } catch (Exception e) {
            log.error(e.getMessage());
            return RestResult.failResult("医生取消叫号失败！", 500);
        }
    }

    @ApiOperation("医生就诊完成")
    @GetMapping("docFinish")
    public RestResult docFinish(@RequestParam String customerId, @RequestParam String checkProjectId, @RequestParam String docName) {
        try {
            return doctorService.docFinish(customerId, checkProjectId, docName);
        } catch (Exception e) {
            log.error(e.getMessage());
            return RestResult.failResult("医生就诊完成失败！", 500);
        }
    }


}
